package com.kuang.controller.product;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.kuang.auth.CheckLogin;
import com.kuang.common.anno.IgnoreToken;
import com.kuang.common.base.BaseController;
import com.kuang.entity.Product;
import com.kuang.limit.anno.AccessIpLimiter;
import com.kuang.service.ProductService;
import com.kuang.vo.ProductVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class ProductController extends BaseController {

    private static final Logger log = LoggerFactory.getLogger(ProductController.class);
    @Autowired
    private ProductService productService;

    /**
     * 产品查询接口
     * @param productVo
     * @return
     */
    @GetMapping("/product/list")
    @AccessIpLimiter(limit = 10, timeout = 1)
    @IgnoreToken
    @CheckLogin
    public Page<Product> productList(ProductVo productVo) {
        log.info("你输入的参数是：{}",productVo);
        return productService.findProductByPage(productVo);
    }


    /**
     * @author 飞哥yykk
     * @version: 1.0
     * @description: 小程序首页查询
     * 用处：微信小程序的产品tabbar中的产品接口
     * @date 2021/8/30 21:20
     */
    @GetMapping("/product/index")
    @AccessIpLimiter(limit = 10, timeout = 1)
    @IgnoreToken
    public Page<Product> findProductByPageIndex(ProductVo productVo){
        log.info("你输入的参数是：{}",productVo);
        return productService.findProductByPage(productVo);
    }

    /**
     * 查询产品明细
     * @param id
     * @return
     */
    @GetMapping("/product/get/{id}")
    @AccessIpLimiter(limit = 5, timeout = 1)
    @IgnoreToken
    public Product getProduct(@PathVariable("id") Long id) {
        return productService.getProductDetail(id);
    }
}
